<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::namespace('api')->prefix('v1')->middleware('cors')->group(function () {

    Route::middleware('api.guard')->group(function () {
        Route::post('users', 'UserController@store')->name('users.store'); // 用户注册
        Route::post('login', 'UserController@login')->name('users.login'); // 用户登录

        Route::middleware('api.refresh')->group(function () {
            Route::get('users/info', 'UserController@info')->name('users.info'); // 返回当前登录用户信息

            Route::get('users', 'UserController@index')->name('users.index'); // 用户列表
            Route::get('users/{user}', 'UserController@show')->name('users.show'); // 单一用户信息
            Route::delete('logout', 'UserController@logout')->name('users.logout'); // 用户退出
        });
    });



    Route::middleware('admin.guard')->group(function () {

        Route::post('admins', 'AdminController@store')->name('admins.store'); // 管理员注册
        Route::post('admin/login', 'AdminController@login')->name('admins.login'); // 管理员登录

        Route::middleware('admin.refresh')->group(function () {
            Route::get('admins/info', 'AdminController@info')->name('admins.info'); // 返回当前管理员信息

            Route::get('admins', 'AdminController@index')->name('admins.index'); // 管理员列表
            Route::get('admins/{admin}', 'AdminController@show')->name('admins.show'); // 单一管理员信息
            Route::delete('admins/logout', 'AdminController@logout')->name('admins.logout'); // 管理员退出
        });


    });


});
